package com.trkj.service.mapper;

import java.math.BigDecimal;
import java.sql.Timestamp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.trkj.dao.wdm.DutyDAO;
import com.trkj.dao.wdm.PChangeDAO;
import com.trkj.dao.wdm.StaffInformationDAO;
import com.trkj.mybatisdao.PositionChangeDAO;
import com.trkj.pojo.Duty;
import com.trkj.pojo.PositionChange;
import com.trkj.pojo.StaffInformation;

@Service
@Transactional(rollbackFor = Exception.class)
public class PostitionChangeService {
	@Autowired
	private PositionChangeDAO positionChangeDAO;
	@Autowired
	private DutyDAO ddao;
	@Autowired
	private StaffInformationDAO sdao;
	@Autowired
	private PChangeDAO pdao;
	
	public JSONArray findAll(){
		return positionChangeDAO.findAll();
		
	}
	
	
	
	
	/**
	 * 新增员工职务变动信息
	 */
	public void insertStaffTurnOver(Long id,Long id2,Timestamp time,String person){
		PositionChange pc = new PositionChange();
		StaffInformation staff = sdao.findOne(id);
		pc.setInitialPositionId(new BigDecimal(staff.getDuty().getDutyId()));
		
		Duty d = ddao.findOne(id2);
		staff.setDuty(d);
		sdao.save(staff);
		pc.setVariationPositionId(new BigDecimal(id2));
		pc.setStaffInformation(staff);
		pc.setVariationPositionDate(time);
		pc.setPoExecutor(person);
		pdao.save(pc);
	}
	
	
	/**
	 * 删除职务变动信息
	 * @param id
	 * @param beizhu
	 */
	public void deleteStaffTurnOver(Long id){
		pdao.delete(id);
	}
	/**
	 * 模糊查询员工职务变动所有
	 * @return
	 */
	public JSONArray findStaffTurnOverLikeAll(String name){
		return positionChangeDAO.findLikeAll("%"+name+"%");
	}
}
